<template>
	<view class="smart-padding-wrap uni-common-mt">
		<view class="smart-panel-title uni-common-mt">默认样式</view>
		<view>
			<checkbox-group>
				<checkbox checked="true"></checkbox>选中
				<checkbox></checkbox>未选中
			</checkbox-group>
		</view>

		<view class=" smart-panel-title uni-common-mt">不同颜色和尺寸的checkbox</view>
		<view>
			<checkbox-group>
				<checkbox checked="true" style="transform:scale(0.7)" color="#8A6DE9"></checkbox>选中
				<label style="background-color:#8A6DE9;">
					<checkbox style="transform:scale(0.7)"></checkbox>未选中
				</label>
			</checkbox-group>
		</view>
		<view class="">
			<checkbox-group @change="checkboxChange">
				<label class="checkbox-item"  v-for="item in items" :key="item.value">
					:class="{ 'selected': item.checked }">
					<view>
						<checkbox :value="item.value" :checked="item.checked" />
					</view>
					<view>{{item.name}}</view>
				</label>
			</checkbox-group>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				items: [{
						name: 'HTML',
						value: 'html',
						checked: false
					},
					{
						name: 'CSS',
						value: 'css',
						checked: false
					},
					{
						name: 'JavaScript',
						value: 'js',
						checked: false
					},
					{
						name: 'Vue.js',
						value: 'vue',
						checked: false
					},
					{
						name: 'UniApp',
						value: 'uniapp',
						checked: false
					},
					{
						name: 'Node.js',
						value: 'node',
						checked: false
					},
					{
						name: 'TypeScript',
						value: 'ts',
						checked: false
					}
				],
				selectedItems: []
			}
		},
		methods: {
			checkboxChange: function(e) {
				this.items.forEach(item => {
					item.checked = e.detail.value.includes(item.value)
				})
				this.selectedItems = this.items
					.filter(item => item.checked)
					.map(item => item.name)

				// 可以在这里添加提交逻辑或触发其他操作
				console.log('当前选中:', this.selectedItems)
			}

		}
	}
</script>

<style>
	.checkbox-item {
		background-color:#F3A73F;
		display: flex;
		align-items: center;
		padding: 20rpx 0;
		margin-right: 30rpx;
		font-size: 30rpx;
	}
</style>